//
//  OrderFootTimeTableViewHeaderFooterView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/26.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "OrderFootTimeTableViewHeaderFooterView.h"

@implementation OrderFootTimeTableViewHeaderFooterView
{
    NSMutableArray *btnArr;
    GLGWLabel *bottomLeftLabel;
//    GLGWLabel *timeLab;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        GLGWView *bakTopView = [[GLGWView alloc] initWithInSuperView:self.contentView];
        bakTopView.backgroundColor = [UIColor whiteColor];
        [bakTopView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView).offset(0);
        }];
    
        btnArr = [NSMutableArray array];
        CGFloat butWidth = KScreenWidth - kWidthProportion_In_iPhoneTriploid(75)*4 -kWidthProportion_In_iPhoneTriploid(45);
        for (int i=0; i<4; i++) {
            NSString *str = [NSString stringWithFormat:@"%d",i];
            GLGWButton *bottomBut = [[GLGWButton alloc] initWithFrame:CGRectMake(butWidth+kWidthProportion_In_iPhoneTriploid(75)*i+kWidthProportion_In_iPhoneTriploid(10)*i, kHeightProportion_In_iPhoneTriploid(15), kWidthProportion_In_iPhoneTriploid(75), kHeightProportion_In_iPhoneTriploid(30)) hTitle:str titleLableFont:SYSTEMFONT(12) titleLableColor:[UIColor colorWithHexString:@"#666666"] theCornerRadius:kHeightProportion_In_iPhoneTriploid(15) theBorderWidth:1.0 theBorderColor:kColor_Rule_Yellow backgroundColr:[UIColor whiteColor] inSuperView:self];
            [bottomBut addTarget:self action:@selector(proButAction:) forControlEvents:UIControlEventTouchUpInside];
            [btnArr addObject:bottomBut];
        }
        //
        GLGWLabel *timeLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.contentView];
        timeLabel.text = @"剩余00:30:30";
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(18));
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(15));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
        _timeLabel = timeLabel;
        
        GLGWLabel *bottomLeftLab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.contentView];
        bottomLeftLab.text = @"分享给客户";
        [bottomLeftLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(timeLabel.mas_left).offset(-kWidthProportion_In_iPhoneTriploid(20));
            make.bottom.equalTo(timeLabel.mas_bottom);
            make.height.equalTo(timeLabel.mas_height);
        }];
        bottomLeftLabel = bottomLeftLab;        
        
    }
    return self;
}
- (void)proButAction:(GLGWButton *)sender
{
    if (self.Block_PayAction) {
        self.Block_PayAction(sender, self.section);
    }
}

- (void)setDetailListModel:(AllOrderDetailListModel *)detailListModel
{
    _detailListModel = detailListModel;  // 这里是买家去支付的状态
    // 1：确认中(卖家：待您确认，买家/自由经理人：卖家确认中)2：待支付；3：线下支付待确认；4：待商家发货；5：待收货；6：交易完成；18：支付超时；19：订单取消
    NSInteger cout = 340;
    for (int i = 0; i < btnArr.count; i ++) {
        GLGWButton *btn = btnArr[i];
        if (i == 0) {
            if (self.accountType == AccountType_FreeManagers) { // 有分享也有时间
                bottomLeftLabel.hidden = NO;
                bottomLeftLabel.text = @"剩余00:30:30";
                _timeLabel.text = @"分享给客户";
                [self btnStatus:btn titleStr:@"更多" textColor:@"#666666" layerColor:@"#FFFFFF" tag:cout + 8];
            } else {
                bottomLeftLabel.hidden = YES;
                _timeLabel.text = @"剩余00:30:30";
                [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
            }
        } else if (i == 1) {
            [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];

        } else if (i == 2) {
            if (self.accountType == AccountType_FreeManagers) {
                [self btnStatus:btn titleStr:@"去支付" textColor:@"#EC5353" layerColor:@"#EC5353" tag:cout + 4];
            } else {
                [self btnStatus:btn titleStr:@"取消订单" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 3];
            }

        } else if (i == 3) {
            if (self.accountType == AccountType_FreeManagers) {
                [self btnStatus:btn titleStr:@"去支付" textColor:@"#EC5353" layerColor:@"#EC5353" tag:cout + 9];
            } else {
                [self btnStatus:btn titleStr:@"去支付" textColor:@"#EC5353" layerColor:@"#EC5353" tag:cout + 4];
            }
        }
    }
}

- (void)btnStatus:(GLGWButton *)btn titleStr:(NSString *)titleStr textColor:(NSString *)colorStr layerColor:(NSString *)layerColorStr tag:(NSInteger)tag
{
    [btn setTitle:titleStr forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:colorStr] forState:UIControlStateNormal];
    btn.layer.borderColor = [UIColor colorWithHexString:layerColorStr].CGColor;
    btn.tag = tag;
    btn.hidden = NO;
}
@end
